class MoviePic < ActiveRecord::Base
  
  belongs_to :movie
  
  acts_as_attachment(:content_type => :image,
                 :processor => :Rmagick,
                 :storage => :file_system,
                 :resize_to => '620x480>',
                 :thumbnails => {:cover => '300x390>',
                 :thumb => '70x70>' }
                 )
          
  validates_as_attachment
  
  def self.batch_create(options = {})
    @attachment = {}
    @flash = ''
    options[:attachments].each { |key, value|
      @attachment[:uploaded_data] = value
      @movie_pic = MoviePic.new(@attachment)
      @movie_pic.movie_id = options[:movie_id]
      puts value
      begin
        @movie_pic.save!
      rescue Exception => exc
        logger.error("#{key} is invalid !")
        @flash << "#{key} "
        @exception = "true"
      end
      }
      str = {}
      str[:exception] = @exception
      str[:flash] = @flash
      str
  end
  
end
